package com.weiz.appb.controller;

import com.weiz.appb.entity.ReturnEntity;
import com.weiz.appb.util.HttpClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类功能简述：
 * 类功能详述：
 *
 * @author weiz
 *  2019/3/1 14:08
 */
@Controller
public class IndexController {

    @Value("${sso_server}")
    private String serverHost;

    @RequestMapping({"/","/index"})
    public String index() {
        return "index";
    }

    @RequestMapping("/test")
    @ResponseBody
    public ReturnEntity test() {
        return new ReturnEntity(1, "通过验证", null);
    }

    @RequestMapping("/logout")
    public void logout(HttpServletRequest request, HttpServletResponse response,String token) throws Exception {
        HttpClient.get(serverHost + "/inValid?token=" + token);
        String requestHost = request.getScheme() +"://"+ request.getServerName() + ":"+request.getServerPort() +"/";
        String redirect = serverHost + "/login?redirect=" + requestHost;
        System.out.println(redirect);
        response.sendRedirect(redirect);
    }
}
